//
//  Created by  fred on 2017/1/12.
//  Copyright © 2016年 Alibaba. All rights reserved.
//

package com.ian.commons;

import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;

public class HttpsApiClient extends ApacheHttpClient {
    public final static String HOST = "smsapi.api51.cn";
    static HttpsApiClient instance = new HttpsApiClient();

    public static HttpsApiClient getInstance() {
        return instance;
    }

    @Override
    public void init(HttpClientBuilderParams httpClientBuilderParams) {
        httpClientBuilderParams.setScheme(Scheme.HTTPS);
        httpClientBuilderParams.setHost(HOST);
        super.init(httpClientBuilderParams);
    }


    public void 语音验证码(String mobile, String code, ApiCallback callback) {
        String path = "/voice_sendcode";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);
        request.addParam("code", code, ParamPosition.QUERY, true);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse 语音验证码SyncMode(String mobile, String code) {
        String path = "/voice_sendcode";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);
        request.addParam("code", code, ParamPosition.QUERY, true);


        return sendSyncRequest(request);
    }

    public void DIY短信接口POST版本(String mobile, String sign, Integer tpl_id, String params, ApiCallback callback) {
        String path = "/single_sms/";
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM, path);
        request.addParam("mobile", mobile, ParamPosition.BODY, true);
        request.addParam("sign", sign, ParamPosition.BODY, true);
        request.addParam("tpl_id", String.valueOf(tpl_id), ParamPosition.BODY, true);
        request.addParam("params", params, ParamPosition.BODY, true);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse DIY短信接口POST版本SyncMode(String mobile, String sign, Integer tpl_id, String params) {
        String path = "/single_sms/";
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM, path);
        request.addParam("mobile", mobile, ParamPosition.BODY, true);
        request.addParam("sign", sign, ParamPosition.BODY, true);
        request.addParam("tpl_id", String.valueOf(tpl_id), ParamPosition.BODY, true);
        request.addParam("params", params, ParamPosition.BODY, true);


        return sendSyncRequest(request);
    }

    public void DIY短信接口GET版本(String mobile, String sign, String tpl_id, String params, ApiCallback callback) {
        String path = "/single_sms_get/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);
        request.addParam("sign", sign, ParamPosition.QUERY, true);
        request.addParam("tpl_id", tpl_id, ParamPosition.QUERY, true);
        request.addParam("params", params, ParamPosition.QUERY, false);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse DIY短信接口GET版本SyncMode(String mobile, String sign, String tpl_id, String params) {
        String path = "/single_sms_get/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);
        request.addParam("sign", sign, ParamPosition.QUERY, true);
        request.addParam("tpl_id", tpl_id, ParamPosition.QUERY, true);
        request.addParam("params", params, ParamPosition.QUERY, false);


        return sendSyncRequest(request);
    }

    public void 提示风险验证码(String code, String mobile, ApiCallback callback) {
        String path = "/risk_code";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse 提示风险验证码SyncMode(String code, String mobile) {
        String path = "/risk_code";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        return sendSyncRequest(request);
    }

    public void 尊敬的XX您的验证吗是XXXX(String code, String name, String mobile, ApiCallback callback) {
        String path = "/name/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("name", name, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse 尊敬的XX您的验证吗是XXXXSyncMode(String code, String name, String mobile) {
        String path = "/name/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("name", name, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        return sendSyncRequest(request);
    }

    public void 您的验证码是XXX(String code, String mobile, ApiCallback callback) {
        String path = "/code/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        sendAsyncRequest(request, callback);
    }

    public ApiResponse 您的验证码是XXXSyncMode(String code, String mobile) {
        String path = "/code/";
        ApiRequest request = new ApiRequest(HttpMethod.GET, path);
        request.addParam("code", code, ParamPosition.QUERY, true);
        request.addParam("mobile", mobile, ParamPosition.QUERY, true);


        return sendSyncRequest(request);
    }

}